//
// Created by xili on 2024/8/21 18:39.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int magicalString(int n) {
        vector<int> tmp{1, 2, 2};
        int ans = 1;
        for (int i = 2, j = 2; i < n; i++) {
            if (tmp[i] == 1)ans++;
            int newnum = 1;
            if (tmp.back() == 1)newnum = 2;
            int count = tmp[i];
            while (count--)tmp.push_back(newnum);
        }
        return ans;
    }
};